<?php

namespace app\admin\controller\shop;

use app\common\controller\Backend;
use think\exception\ValidateException;
use Throwable;

class Base extends Backend
{
    protected array $noNeedLogin = ['config'];

    protected string $validateName = '';

    /**
     * 数据校验
     * @param array  $data  校验数据
     * @param string $scene 校验场景
     */
    protected function validateData(array $data, string $scene = ''): void
    {
        if (class_exists($this->validateName)) {
            try {
                $validate = validate($this->validateName);
                if ($scene) {
                    $validate->scene($scene);
                }
                $validate->check($data);
            } catch (ValidateException $e) {
                $this->error($e->getMessage());
            }
        }
    }

    public function config(): void
    {
        try {
            $notify = $this->auth->check('shop/notify/notify');
        } catch (Throwable) {
            $notify = false;
        }

        $this->success('', [
            'notify' => $notify
        ]);
    }
}